package com.xsq.consumer.dubboconsumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xsq.api.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName TestController
 * @Description TODO
 * @Author xsq
 * @Date 2020/6/24 14:26
 **/
@RestController
@Slf4j
public class TestController {

    private ExecutorService executorService = new ThreadPoolExecutor(100, 200, 5, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(2000));

    @Reference
    private TestService testService;

    @RequestMapping("/test")
    public String test(@RequestParam  int count) {
        for (int i = 0; i < count; i++) {
            executorService.execute(() -> {
                log.info(testService.order());
                log.info(testService.pay());
                log.info(testService.shipments());
            });
        }
        return "交易完成";
    }
}
